<template>
  <div id="forumpage"
       :style="{background: 'url('+bgimgBtn+')',backgroundRepeat: 'no-repeat',backgroundSize: '100% 100%'}">
    <div class="forum">
      <div class="header-out">
        <div class="header">
          <div class="headerleft">
            <img src="@/assets/imageAdmin/logo.jpg" alt="">
            小森林圈
          </div>
          <div class="headerright">
            <el-input placeholder="搜索你感兴趣的内容标题" size="small"></el-input>
            <span class="el-icon-search"></span>
          </div>
        </div>
      </div>
      <div class="rourmCenter">
        <div class="rourmCenter-centent">
          <div class="nexttitle">
            <!--<el-page-header @back="goBack" content="论坛文章审核()"></el-page-header>-->
            <!--{{page.total}}-->
            <el-page-header @back="goBack" :content="'我的文章('+page.total+')'"></el-page-header>
          </div>
          <div class="tableboxTab">
            <el-radio-group v-model="formData.is_examine" size="small" class="mb-10" @change="tabList">
              <el-radio-button :label="1">发布文章</el-radio-button>
              <el-radio-button :label="2">驳回文章</el-radio-button>
            </el-radio-group>
            <el-table
                    ref="multipleTable"
                    :data="arryList"
                    :stripe="tableStyle.tableStripe"
                    :border="tableStyle.tableBorder"
                    tooltip-effect="dark"
                    style="width: 100%"
                    header-cell-class-name="table-text-c"
                    cell-class-name="table-text-c">
              <el-table-column
                      align="center"
                      prop="title"
                      label="文章标题">
              </el-table-column>
              <el-table-column
                      align="center"
                      label="版块">
                <template slot-scope="scope">
                  {{scope.row.plate.name}}
                </template>
              </el-table-column>
              <el-table-column
                      prop="create_time"
                      align="center"
                      label="发布时间">
              </el-table-column>
              <el-table-column
                      prop="comment_number"
                      align="center"
                      label="评论数"
                      v-if="formData.is_examine==1"
                      key="1">
              </el-table-column>
              <el-table-column
                      prop="laud"
                      align="center"
                      label="点赞数"
                      v-if="formData.is_examine==1"
                      key="2">
              </el-table-column>
              <el-table-column
                      prop="content"
                      align="center"
                      label="驳回理由"
                      v-if="formData.is_examine==2"
                      key="3">
              </el-table-column>
              <el-table-column
                      align="center"
                      label="操作"
                      width="100">
                <template slot-scope="scope">
                  <el-button size="small" @click="gotolist(scope.$index)">详情</el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-col :span="24" class="toolbar">
              <el-pagination
                      background
                      layout="total, prev, pager, next"
                      :total="page.total"
                      :page-size="page.pagesize"
                      @current-change="handleSizeChange">
              </el-pagination>
            </el-col>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import bgimgBtn from '@/assets/imageAdmin/bgforue.png'
  import {pagination, tableoption} from '@/utils/util.js'
  import {mapGetters} from "vuex";

  export default {
    data () {
      return {
        tableStyle: tableoption,
        // 设置table页面分页所需
        page: {
          pageindex: pagination.pageIndex,
          pagesize: pagination.pageSize,
          total: pagination.total
        },
        arryList: [], // 页面数据列表
        bgimgBtn: bgimgBtn,
        userInfomation: null,
        status: 1, // 0未审核 1通过 2驳回
        formData: {
          is_examine: 1,
          user_id: null,
          p: 1
        }
      }
    },
    computed: {
      ...mapGetters(['userInfo']),
    },
    created () {
      this.formData.user_id = this.userInfo.id
      this.InitFn()
    },
    methods: {
      InitFn () {
        // is_examine审核状态，user_id
        // 0未审核 1通过 2驳回
        this.formData.p = this.page.pageindex
        this.$fetch(this.api.forum_postings_index, this.formData).then((response) => {
          if (response.code === 0) {
            for (let i in response.list.data) {
              response.list.data[i].create_time = response.list.data[i].create_time.split(' ')[0]
            }
            this.arryList = response.list.data
            this.page.total = response.list.total
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      tabList () {
        //  radio1
        this.page.pageindex = 1
        this.arryList = []
        this.InitFn()
      },
      gotolist (index) {
        // type 1 列表进入 2 审核进入
        if (this.formData.is_examine === 1) {
          this.$router.push('/forumdetail?type=1&id=' + this.arryList[index].id)
        } else {
          this.$router.push('/forumarticledit?editId=' + this.arryList[index].id)
        }
      },
      // 分页
      handleSizeChange (val) {
        this.page.pageindex = val
        this.InitFn()
      },
      goBack () {
        this.$router.go(-1)
      },
      getqrcode (index) {
        this.$confirm('确定通过审核，发布该版块文章?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.checkSuccessFn(index)
        }).catch(() => {

        })
      },
      checkSuccessFn (index) {
        // 0待审核1审核2驳回 is_examine
        this.$post(this.api.forum_postings_adopt, {
          id: this.arryList[index].id
        }).then((response) => {
          if (response.code === 0) {
            this.InitFn()
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      detelTearch (index) {
        this.$prompt('请填写相应的驳回理由，以便记录更改', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({value}) => {
          console.log('输入的内容：', value)
          if (!value) {
            this.$message.error('请填写相应的驳回理由')
          } else {
            this.checkFailFn(index, value)
          }
        }).catch(() => {
        })
      },
      checkFailFn (index, value) {
        // 0待审核1审核2驳回 is_examine
        this.$post(this.api.admin_notice_reject, {
          id: this.arryList[index].id,
          content: value
        }).then((response) => {
          if (response.code === 0) {
            this.InitFn()
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      }
    },
    mounted () {
    }
  }
</script>


